package main

import (
	"book-management-system/models"
	"book-management-system/repositories"
	"book-management-system/routes"
	"gorm.io/driver/sqlite"
	"gorm.io/gorm"
)

func main() {
	// Initialize database connection
	db, err := gorm.Open(sqlite.Open("books.db"), &gorm.Config{})
	if err != nil {
		panic("failed to connect to database")
	}

	// Migrate models
	db.AutoMigrate(&models.Book{}, &models.User{}, &models.BorrowRecord{})

	// Set DB to repository
	repositories.SetDatabase(db)

	// Start Gin server
	r := routes.SetupRouter()
	r.Run(":8080")
}
